package com.weirong.smartvault.backservice.controller;

import com.weirong.smartvault.dao.DepartmentRepository;
import com.weirong.smartvault.entity.Department;
import com.weirong.smartvault.tools.BuildMockRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;

import java.util.List;

import static org.hamcrest.Matchers.hasItems;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;

/**
 * Created by KFEB4 on 2017/11/19.
 */

@RunWith(SpringRunner.class)
@SpringBootTest
public class test_base {
    @Test
    public void test_add_org_template_load() throws Exception {
        Base base = new Base();

        MockMvc mockMvc = standaloneSetup(base).build();
        mockMvc.perform(get("/base/add_org")).andExpect(view().name("base/add_org"));
    }

    @Test
    public void test_add_org_post_department(){
        //TODO 测试add_org的push方法，由于实体结构和网页布局不一致，暂时不做测试
    }

    @Test
    public void test_org_template_load() throws Exception {
        //测试机构详情界面
        List<Department> departments = BuildMockRepository.departmentsList();
        DepartmentRepository departmentRepository = BuildMockRepository.departmentRepository(departments);
        Base base = new Base();
        MockMvc mockMvc = standaloneSetup(base).build();
        mockMvc.perform(get("/base/orgGet"))
                .andExpect(view().name("base/orgGet"))
                .andExpect(model().attributeExists("departments"))
                .andExpect(model().attribute("departments", hasItems(departments.toArray())));
    }
}
